<template>
  <!-- 非正式供应商 -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <j-input placeholder="请输入企业名称" v-model="queryParam.enterpriseName"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep :multi="false" v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="addOrEdit('')" type="primary" icon="plus" :disabled="isDisabledAuth('erpPurchaseFormalSupplier:add')">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x: '100%'}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <template>
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="addOrEdit(record)"
              :disabled="isDisabledAuth('erpPurchaseFormalSupplier:edit')"
            />
            <a-divider type="vertical" v-has="'erpPurchaseFormalSupplier:delete'"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-has="'erpPurchaseFormalSupplier:delete'">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpPurchaseFormalSupplier:delete')"/>
            </a-popconfirm>

          </template>
        </span>

      </a-table>
    </div>

    <erp-purchase-supplier-modal ref="modalForm" @ok="modalFormOk"/>
    <unSupplierForm ref="unSupplier" @ok="loadData(1)"/>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpPurchaseSupplierModal from './modules/ErpPurchaseSupplierModal'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import { getAction, putAction } from '@api/manage'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import unSupplierForm from './comp/unSupplierForm.vue'

  export default {
    name: 'ErpPurchaseSupplierList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpPurchaseSupplierModal,
      SelectUserByDep,
      unSupplierForm
    },
    data () {
      return {
        // 列定义
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            ellipsis: true,
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '申请人',
            align: 'center',
            ellipsis: true,
            width: 90,
            dataIndex: 'proposer_dictText'
          },
          {
            title: '申请部门',
            align: 'center',
            ellipsis: true,
            width: 150,
            dataIndex: 'proposerDeptId_dictText'
          },
          {
            title: '企业名称',
            align: 'center',
            ellipsis: true,
            width: 300,
            dataIndex: 'enterpriseName'
          },
          {
            title: '企业信用代码',
            width: 180,
            align: 'center',
            ellipsis: true,
            dataIndex: 'enterpriseCreditCode'
          },
          {
            title: '企业地址',
            align: 'center',
            ellipsis: true,
            width: 300,
            dataIndex: 'enterpriseAddress'
          },
          {
            title: '合作业务',
            align: 'center',
            ellipsis: true,
            width: 300,
            dataIndex: 'mainBussiness'
          },
          {
            title: '联系人',
            align: 'center',
            ellipsis: true,
            width: 90,
            dataIndex: 'liaison'
          },
          {
            title: '联系电话',
            align: 'center',
            ellipsis: true,
            width: 120,
            dataIndex: 'liaisonMobile'
          },
          {
            title: '开户行',
            align: 'center',
            ellipsis: true,
            width: 300,
            dataIndex: 'bankName'
          },
          {
            title: '银行账号',
            align: 'center',
            ellipsis: true,
            width: 200,
            dataIndex: 'bankAccountNo'
          },
          {
            title: '操作',
            dataIndex: 'action',
            fixed: 'right',
            align: 'center',
            width: 147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/purchase/supplier/erpPurchaseSupplier/supplierList?commercialType=2',
          delete: '/api/erp/purchase/supplier/erpPurchaseSupplier/deleteSupplierId',
          deleteBatch: '/api/erp/purchase/supplier/erpPurchaseSupplier/deleteBatchSupplier'
        }
      }
    },
    methods: {
      searchReset() {
        this.queryParam = {}
        this.loadData(1)
      },
      addOrEdit(record) {
        this.$refs.unSupplier.getInitData(record)
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
